clear all
set more off
	
global dir "C:\Users\mrueda\Documents\Emory\Papers\Networks_persistance\do_files\do_files_APSA21\post_JOP\Replication_BJPS\"

cd "$dir"


	texdoc close 
	cap erase "$dir/Tables/TableH2.tex"
	texdoc init "$dir/Tables/TableH2.tex", force
	
	tex \begin{table}[tbph]
	tex \caption{Effect of donating to an election winner on future donations (candidate's family members vs. Non members, local councils)}\label{tab:donation_fam_nofam_council}
	tex \centering
	tex \begin{tabular}{l c c H} \hline
	tex Outcome : & Any race & Council & b2 \\ 
	tex & (1) & (2) & (3) \\ \hline
	tex \multicolumn{2}{l}{Panel A: Candidates' family members}&\\
	tex & & & \\
	
	*Model 1
	foreach x in donate_any15 b5{
	
		
		use "$dir\Data\council_cand_level_persist_rep.dta",clear
		
		drop if fall==.
		gen treat=0
		replace treat=1 if rv2>0&rv2~=.
		replace treat=. if rv2==.

		gen treat_rv2=treat*rv2
				
		*Family
		*Regressions
		*Summary statistics for the mean
		quietly sum f`x' 
			local fmean_`x' : di %5.3f r(mean)
			local sd_`x' : di %5.3f r(sd) 
			
		rdrobust f`x' rv2 ,  vce(cluster muni_code)

		*Local's for the table
		local fbw_`x' : di %5.2f `e(h_l)'
		local fNeff_`x' = `e(N_h_l)'+`e(N_h_r)'
		local fN_`x' = `e(N)'
		local fbeta1_`x' : di %5.3f `e(tau_cl)'
		local fbeta2_`x' : di %5.3f `e(tau_bc)'

		*Confidence intervals
			local fser1_`x' : di %5.3f `e(ci_l_rb)'
			local fser2_`x' : di %5.3f `e(ci_r_rb)'
			
/* HERE*/	local fem1_`x' = (`fbeta1_`x''/`fmean_`x'')*100 
			local fem1_`x' : di %5.2f `fem1_`x''
			
		*P-values
		local fpval2_`x' : di %5.3f `e(pv_rb)'
		scalar fpval2_`x' = e(pv_rb)
		
		
		regress f`x' treat treat_rv2 rv2, vce(cluster muni_code)

		local fN_`x' : di %5.0f e(N)
		local fR2_`x' : di %5.3f e(r2)

		matrix b = e(b)
		matrix v = e(V)
		matrix res=r(table)
		
		local fb1_`x' : di %5.3f b[1,1]
		local fse1_`x' : di %5.3f sqrt(v[1,1])
		local fp_v_`x' :di %5.3f res[4,1]
		local fuci_`x': di %5.3f res[6,1]
		local flci_`x': di %5.3f res[5,1]
		
		use "$dir\Data\council_cand_level_persist_rep.dta",clear
		
		gen treat=0
		replace treat=1 if rv2>0&rv2~=.
		replace treat=. if rv2==.

		gen treat_rv2=treat*rv2
		
		*No Family
		*Regressions
		*Summary statistics for the mean
		quietly sum nf`x' 
			local nfmean_`x' : di %5.3f r(mean)
			local sd_`x' : di %5.3f r(sd) 

		rdrobust nf`x' rv2 ,  vce(cluster muni_code)

		*Local's for the table
		local nfbw_`x' : di %5.2f `e(h_l)'
		local nfNeff_`x' = `e(N_h_l)'+`e(N_h_r)'
		local nfN_`x' = `e(N)'
		local nfbeta1_`x' : di %5.3f `e(tau_cl)'
		local nfbeta2_`x' : di %5.3f `e(tau_bc)'

		*Confidence intervals
			local nfser1_`x' : di %5.3f `e(ci_l_rb)'
			local nfser2_`x' : di %5.3f `e(ci_r_rb)'
			
/* HERE*/	local nfem1_`x' = (`nfbeta1_`x''/`nfmean_`x'')*100 
			local nfem1_`x' : di %5.2f `nfem1_`x''
			
		*P-values
		local nfpval2_`x' : di %5.3f `e(pv_rb)'
		scalar nfpval2_`x' = e(pv_rb)
		
		regress nf`x' treat treat_rv2 rv2 , vce(cluster muni_code)

		local nfN_`x' : di %5.0f e(N)
		local nfR2_`x' : di %5.3f e(r2)

		matrix b = e(b)
		matrix v = e(V)
		matrix res=r(table)
		
		local nfb1_`x' : di %5.3f b[1,1]
		local nfse1_`x' : di %5.3f sqrt(v[1,1])
		local nfp_v_`x' :di %5.3f res[4,1]
		local nfuci_`x': di %5.3f res[6,1]
		local nflci_`x': di %5.3f res[5,1]

	}
	


		

	*Continue table
	tex \multicolumn{2}{l}{Local linear}\\
	tex Electoral victory & `fbeta1_donate_any15' & `fbeta1_b5' & `fbeta1_b3' \\
	tex \ \ \ \ Robust p-value & `fpval2_donate_any15' & `fpval2_b5' & `fpval2_b3' \\
	tex \ \ \ \ CI 95\%  & [`fser1_donate_any15',`fser2_donate_any15'] & [`fser1_b5',`fser2_b5'] & [`fser1_b3',`fser2_b3'] \\
	tex & & & \\
	
	tex \multicolumn{2}{l}{Parametric (linear)}\\
	tex Electoral victory & `fb1_donate_any15' & `fb1_b5'  \\
	tex \ \ \ \ Robust p-value & `fp_v_donate_any15' & `fp_v_b5' \\
	tex \ \ \ \ CI 95\%  & [`flci_donate_any15',`fuci_donate_any15'] & [`flci_b5',`fuci_b5']  \\
	tex & & & \\
	
	tex Observations & `fN_donate_any15' & `fN_b5' & `fN_b3' \\
	tex Bandwidth obs. & `fNeff_donate_any15' & `fNeff_b5' & `fNeff_b3' \\
	tex Mean & `fmean_donate_any15' & `fmean_b5' & `fmean_b3' \\
	tex Bandwidth & `fbw_donate_any15' & `fbw_b5' & `fbw_b3' \\ 
	
	tex & & & \\ \hline
	tex {Panel B: Non-family members}&  \\  
	tex & & & \\

	tex \multicolumn{2}{l}{Local linear}\\
	tex Electoral victory & `nfbeta1_donate_any15' & `nfbeta1_b5' & `nfbeta1_b3' \\
	tex \ \ \ \ Robust p-value & `nfpval2_donate_any15' & `nfpval2_b5' & `nfpval2_b3' \\
	tex \ \ \ \ CI 95\%  & [`nfser1_donate_any15',`nfser2_donate_any15'] & [`nfser1_b5',`nfser2_b5'] & [`nfser1_b3',`nfser2_b3'] \\
	tex & & & \\
	
	tex \multicolumn{2}{l}{Parametric (linear)}\\
	tex Electoral victory & `nfb1_donate_any15' & `nfb1_b5'  \\
	tex \ \ \ \ Robust p-value & `nfp_v_donate_any15' & `nfp_v_b5' \\
	tex \ \ \ \ CI 95\%  & [`nflci_donate_any15',`nfuci_donate_any15'] & [`nflci_b5',`nfuci_b5']  \\
	tex & & & \\
	
	tex Observations & `nfN_donate_any15' & `nfN_b5' & `nfN_b3' \\
	tex Bandwidth obs. & `nfNeff_donate_any15' & `nfNeff_b5' & `nfNeff_b3' \\
	tex Mean & `nfmean_donate_any15' & `nfmean_b5' & `nfmean_b3' \\
	tex Bandwidth & `nfbw_donate_any15' & `nfbw_b5' & `nfbw_b3' \\ \hline
	tex \end{tabular}
	tex \parbox{160mm}{ \footnotesize{ Local linear estimates of average treatment effects at the cutoff estimated with triangular kernel weights and optimal MSE bandwidth. Robust p-values with clustering at the municipality level and 95\% robust confidence intervals are computed following \cite{calonico_robust_2014}. Parametric linear model specification includes interaction of the treatment with the running variable and running variable. Bandwidth obs. denotes the number of observations in the optimal MSE bandwidth.
	tex }
	tex }
	tex \end{table}
	cap texdoc close 
	
	
